<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="renderer" content="webkit">

    <title>生态瞬时评估 - 主页</title>

    <meta name="keywords" content="">
    <meta name="description" content="">

    <!--[if lt IE 9]>
    <meta http-equiv="refresh" content="0;ie.html" />
    <![endif]-->

    <link rel="shortcut icon" href="../favicon.ico">
    <link href="../css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <!--<link href="../css/plugins/iCheck/custom.css" rel="stylesheet">-->
    <link href="../css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="../css/animate.css" rel="stylesheet">
    <link href="../css/style.css?v=4.1.0" rel="stylesheet">
</head>
<body>
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <h3 class="col-sm-offset-3 col-sm-6 text-center">添加实验</h3>
    </div>
    <div class="row">
        <div class="col-sm-offset-3 col-sm-6">
            <form class="form-horizontal" style="margin-top: 20px">
                <div class="form-group">
                    <label for="test-name" class="col-sm-3 control-label">实验名称：</label>
                    <div class="col-sm-8">
                        <input type="text" placeholder="请输入实验名称" class="form-control" id="test-name">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">实验说明：</label>
                    <div class="col-sm-8">
                        <textarea id="test-desc" name="comment" class="form-control" required="" aria-required="true" placeholder="请输入实验说明"></textarea>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">开始时间：</label>
                    <div class="col-sm-8">
                        <input type="text" class="laydate-icon form-control layer-date" id="start-time" placeholder="选择出生日期">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">结束时间：</label>
                    <div class="col-sm-8">
                        <input type="text" class="laydate-icon form-control layer-date" id="end-time" placeholder="选择出生日期">
                    </div>
                </div>
                <div class="form-group">
                    <label for="helpMobile" class="col-sm-3 control-label">心理救助电话：</label>
                    <div class="col-sm-8">
                        <input type="text" placeholder="请输入电话号码" class="form-control" id="helpMobile">
                    </div>
                </div>
                <div class="col-sm-offset-3 col-sm-8">
                    <input type="button" id="addBtn" value="添加" class="btn btn-primary btn-block">
                </div>
            </form>
        </div>
    </div>

</div>




<script src="../js/jquery.min.js?v=2.1.4"></script>
<script src="../js/bootstrap.min.js?v=3.3.6"></script>
<script src="../js/dateChange.js"></script>
<!-- layerDate plugin javascript -->
<script src="../js/plugins/layer/laydate/laydate.js"></script>
<script>
    //日期范围限制
    var start = {
        elem: '#start-time',
        format: 'YYYY-MM-DD hh:mm:ss',
        min: laydate.now(), //设定最小日期为当前日期
        max: '2099-06-16 23:59:59', //最大日期
        istime: true,
        istoday: false,
        choose: function (datas) {
            end.min = datas; //开始日选好后，重置结束日的最小日期
            end.start = datas //将结束日的初始值设定为开始日
        }
    };
    var end = {
        elem: '#end-time',
        format: 'YYYY-MM-DD hh:mm:ss',
        min: laydate.now(),
        max: '2099-06-16 23:59:59',
        istime: true,
        istoday: false,
        choose: function (datas) {
            start.max = datas; //结束日选好后，重置开始日的最大日期
        }
    };
    laydate(start);
    laydate(end);


</script>
<script>
    //提交按钮事件
    $("#addBtn").on("click",function () {
        var $name = $("#test-name").val();
        //console.log($name);
        var $info = $("#test-desc").val();
       // console.log($info);
        var $stime = timeToTimestamp($("#start-time").val());
        var $etime = timeToTimestamp($("#end-time").val());
        var $helpMobile = $("#helpMobile").val();
        var token = sessionStorage.getItem("token");
        var _data = JSON.stringify({"name":$name, "description":$info,"beginDate":$stime,"endDate":$etime,"helpMobile":$helpMobile});
        $.ajax({
            type:"POST",
            url:"http://123.206.18.189:8080/experiments",
            contentType:"application/json",
            headers:{
                authToken:token
            },
            data:_data,
            complete:function (XMLHttpRequest) {
                //console.log(XMLHttpRequest);
                if(XMLHttpRequest.status == 200){
                    alert("添加成功！");
                   //console.log(XMLHttpRequest.readyState);
                    window.history.back(-1);
                }else{
                    alert("添加失败！")
                }
            }
        });

    })
</script>
</body>
</html>